package game;

import cards.Card;
import static game.Player.CardInfo;

import org.testng.annotations.*;
import java.util.*;

@Test(testName="PlayerTest", groups = { "small" })
public class PlayerTest {
  private Player player;
  private Card card;

  @BeforeMethod public void createPlayer() {
    player = new Player(1);
  }

  @BeforeTest public void createCard() {
    card = Card.getCardForString("Qd");
  }

  @Test public void setName() {
    assert player.getName().equals("1") : "Default name not based on id";
    player.setName("Joe Schmoe");
    assert player.getName().equals("Joe Schmoe") : "Unable to set name";
  }

  @Test public void addCard() {
    assert player.getCards().isEmpty();
    player.addCard(card);
    assert player.getCards().size() == 1;
    player.addCard(card);
    assert player.getCards().size() == 2;
    List<CardInfo> cards = player.getCards();
    for (CardInfo ci : cards) {
      assert ci.getCard().equals(card);
    }
  }

  @Test public void discardCard() {
    addCard();
    player.discardCard(card);
    assert player.getCards().size() == 1;
    player.discardCard(card);
    assert player.getCards().isEmpty();
  }

  @Test public void resetCards() {
    addCard();
    assert player.getCards().size() == 2;
    player.resetCards();
    assert player.getCards().isEmpty();
    CardInfo ci = new CardInfo(card, false);
    player.addCard(ci);
    assert ci.getIndex() == 0 : "First insert after reset wasn't 0";
  }
}
